﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace TestRuandao
{
    public class PrincipalForTest : IPrincipal
    {
        IdentityForTest identity;
        string[] roles = null;

        public PrincipalForTest()
        {
            this.identity = new IdentityForTest();
        }

        public PrincipalForTest(string userName, params string[] roles)
        {
            this.identity = new IdentityForTest(userName);
            this.roles = roles;
        }

        #region IPrincipal 成员

        public IIdentity Identity
        {
            get { return this.identity; }
        }

        public bool IsInRole(string role)
        {
            if (roles == null) return false;
            return this.roles.Contains<string>(role);
        }

        #endregion
    }


    public class IdentityForTest : IIdentity
    {
        public IdentityForTest()
        {
            this.isAuthenticated = false;
            this.userName = "Unknown";
        }

        public IdentityForTest(string userName)
        {
            this.isAuthenticated = true;
            this.userName = userName;
        }

        #region IIdentity 成员

        public string AuthenticationType
        {
            get { return "ForTest"; }
        }

        bool isAuthenticated = false;

        public bool IsAuthenticated
        {
            get { return this.isAuthenticated; }
        }

        string userName = "";

        public string Name
        {
            get { return this.userName; }
        }

        #endregion
    }
}
